package com.cans.lightning.base.web;

import com.cans.lightning.base.dto.ResDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常捕获
 *
 * @author shencan
 * @date 2020/9/20 14:23
 */
@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandleConf {

    /**
     * 顶级异常处理
     *
     * @param e 异常信息
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResDto handlerException(Exception e) {

        log.error("全局异常捕获: ", e);

        return ResDto.fait(e.getMessage());
    }
}
